const {
    comMysql
} = require("../db/mysql")

const addNavigation= (req, res) => {
    let {
        category,
        name,
        describe,
        otcName,
        otcDescribe,
        path,
        otcPath,
        bgColor
    } = req.body
    bgColor = bgColor?bgColor:"#fff"
    let sql = `insert into navigation(category,categoryDesc,otcName,otcDescribe,path,otcPath,name,bgColor) values (?,?,?,?,?,?,?,?)`
    let arr = [category, describe, otcName,otcDescribe,path,otcPath,name,bgColor]
    return comMysql(sql, arr)
}
const addSimpleNav = (req, res) => {
    let {
        category,
        name,
        describe,
        otcName,
        otcDescribe,
        path,
        otcPath,
        bgColor
    } = req.body
    !category&&(category="no"); !name&&(name="no"); !describe&&(describe="no"); !otcName&&(otcName="no"); 
    !path&&(path="no"); !otcDescribe&&(otcDescribe="no");
    bgColor = bgColor?bgColor:"#fff"
    let sql = `insert into navigation(category,categoryDesc,otcName,otcDescribe,path,otcPath,name,bgColor) values (?,?,?,?,?,?,?,?)`
    let arr = [category, describe, otcName,otcDescribe,path,otcPath,name,bgColor]
    return comMysql(sql, arr)
}

const deleteNavigation = (req, res) => {
    let {
        id,
    } = req.body
    let sql = `delete from navigation where id = ?`
    let arr = [id]
    return comMysql(sql, arr)
}
const searchNavigation = (req, res) => {
    let {
        id
    } = req.query
    let sql = ""
    let arr
        sql = `select * from navigation`
        arr = [id]
    return comMysql(sql, arr)
}
const updateNavigation = (req, res) => {
    let {
        category,
        name,
        describe,
        otcName,
        otcDescribe,
        path,
        otcPath,
        bgColor,
        id
    } = req.body
    bgColor = bgColor?bgColor:"#fff"
        let sql1 = `update navigation set category = ?,name = ?,categoryDesc = ?,otcName = ?,otcDescribe = ?,
        path = ?, otcPath = ?, bgColor = ? where id = ?`
        let arr1 = [category, name, describe, otcName,otcDescribe,path,otcPath,bgColor,id]
        return comMysql(sql1, arr1)
}
module.exports = {
    addNavigation,
    deleteNavigation,
    searchNavigation,
    updateNavigation,
    addSimpleNav
}